/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author p0838139
 */
package JavaAssignment;

import java.io.*;
import java.util.*;

public class DataManager implements Serializable{

    
    String line;
    int lineCount = 0;
    GameCollection dataList =new GameCollection();
    LinkList reviewList = new LinkList();
    

    public GameCollection loadData(String filename) throws IOException {

        BufferedReader counter = new BufferedReader(new FileReader(filename));
        while ((line = counter.readLine()) != null) {
            lineCount++;
        }
        counter.close();


        BufferedReader br = new BufferedReader(new FileReader(filename));
        for (int i = 0; i < lineCount; i++) {
            String s = br.readLine();
            StringTokenizer st = new StringTokenizer(s, ",");
            String gameName = st.nextToken();
            String gameDesc = st.nextToken();
            String gameCat = st.nextToken();
            double gamePrice = Double.parseDouble(st.nextToken());
            int gameReviewNum = Integer.parseInt(st.nextToken());
            for (int x = 0; x < gameReviewNum; x++) {
                    String gameReviewMag = st.nextToken();
                    String gameReviewRating = st.nextToken();
                    reviewList.addLast(new GameReview(gameReviewMag, gameReviewRating));
            }
            String gameImage = st.nextToken();
            dataList.addGame(new GameData(gameName, gameDesc, gameCat, gamePrice, gameReviewNum, reviewList, gameImage));
        }
        br.close();        
        return dataList;

    }
}
